
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

using Xeno_Race.Graphics;
#endregion

namespace Xeno_Race.GameScreens
{
	/// <summary>
	/// Multiplayer choose track screen
	/// </summary>
	class MultiChooseTrack: IGameScreen
	{
        /// <summary>
        /// Input selection
        /// </summary>
        private int menuSelection = 1;

        /// <summary>
        /// Total number of menu items
        /// </summary>
        private const int totalMenuItems = 3;

		#region Properties
		/// <summary>
		/// Name of this game screen
		/// </summary>
		/// <returns>String</returns>
		public string Name
		{
			get
			{
				return "MultiChooseTrack";
			} // get
		} // Name

		private bool quit = false;
		/// <summary>
		/// Returns true if we want to quit this screen and return to the
		/// previous screen. If no more screens are left the game is exited.
		/// </summary>
		/// <returns>Bool</returns>
		public bool Quit
		{
			get
			{
				return quit;
			} // get
		} // Quit

		/// <summary>
		/// Reset camera when starting.
		/// </summary>
		public bool resetCamera = true;
		#endregion

		#region Constructor
		/// <summary>
        /// Create Choose Character Screen for Multiplayer(2)
		/// </summary>
        public MultiChooseTrack()
		{
		}
		#endregion

		#region Run
		/// <summary>
		/// Run game screen. Called each frame.
		/// </summary>
		/// <param name="game">Form for access to other stuff</param>
		public void Run(XenoGame game)
		{
            // Render background first
            game.RenderMenuBackground();

            // Render menu items
            game.logoImg.Render(36, 22);

            Color useColor = Color.White;

            if (menuSelection == 0)
            {
                useColor = game.fadeXenoRed;
                game.circleSelect.RenderCentered(0.66f, 0.5f, 0.72f, game.fadeXenoRed);
            }
            else
                useColor = Color.White;
            TextureFont.WriteText(710, 420, "Moon (Test Track)", useColor);

            if (menuSelection == 1)
            {
                useColor = game.fadeXenoRed;
                game.circleSelect.RenderCentered(0.26f, 0.7f, 1.28f, game.fadeXenoRed);
            }
            else
                useColor = Color.White;
            TextureFont.WriteText(270, 610, "Destroyed Earth", useColor);

            if (menuSelection == 2)
                useColor = game.fadeXenoRed;
            else
                useColor = Color.White;
            game.backButton.Render(1024 - 300, 768 - 70, useColor);

            game.earth.RenderCentered(0.26f, 0.7f, 0.9f);
            game.moon.RenderCentered(0.66f, 0.5f, 0.7f);

            // Handle Inputs
            if (game.currentInputState.DownButton && !game.previousInputState.DownButton)
            {
                game.Sounds.play(SoundManager.Sound.Sounds.Click);

                if (menuSelection == totalMenuItems - 1)
                    menuSelection = 0;
                else
                    menuSelection++;
            }
            else if (game.currentInputState.UpButton && !game.previousInputState.UpButton)
            {
                game.Sounds.play(SoundManager.Sound.Sounds.Click);

                if (menuSelection == 0)
                    menuSelection = totalMenuItems - 1;
                else
                    menuSelection--;
            }

            if ((game.currentInputState.SelectButton && !game.previousInputState.SelectButton) ||
                (game.currentInputState.AButton && !game.previousInputState.AButton))
            {
                game.Sounds.play(SoundManager.Sound.Sounds.Click);

                switch (menuSelection)
                {
                    case 0: // Start game using track 2 (test)
                        game.switchTrack(0, 1);
                        game.switchTrack(1, 1);
                        game.switchShip(0, 0);
                        game.switchShip(1, 1);
                        game.ships[game.Player.ShipSelection].moveStartPos(false);
                        game.ships[game.Player2.ShipSelection].moveStartPos(true);
                        game.Player.Reset();
                        game.Player2.Reset();
                        game.Reset();
                        game.DrawCollisionTrack = true;
                        game.AddGameScreen(new MultiGame());
                        break;

                    case 1: // Start game using track 1 (destroyed earth)
                        game.switchTrack(0, 0);
                        game.switchTrack(1, 0);
                        game.switchShip(0, 0);
                        game.switchShip(1, 1);
                        game.ships[game.Player.ShipSelection].moveStartPos(false);
                        game.ships[game.Player2.ShipSelection].moveStartPos(true);
                        game.Player.Reset();
                        game.Player2.Reset();
                        game.Reset();
                        game.DrawCollisionTrack = false;
                        game.AddGameScreen(new MultiGame());
                        break;

                    case 2://go back
                        quit = true;
                        break;
                }
            }

            if ((game.currentInputState.ExitButton && !game.previousInputState.ExitButton) ||
                (game.currentInputState.XButton && !game.previousInputState.XButton))
            {
                game.Sounds.play(SoundManager.Sound.Sounds.Click);
                quit = true;
            }
        } // Run(game)
		#endregion
	} // class MainMenu
}